package com.ctvit.cch.web.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ctvit.cch.core.pojo.dto.creative.CreativeIdeaAddDTO;
import com.ctvit.cch.core.pojo.dto.creative.CreativeIdeaEditDTO;
import com.ctvit.cch.core.pojo.dto.creative.CreativeIdeaMyDTO;
import com.ctvit.cch.core.service.ICreativeIdeaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 灵感创意Controller
 *
 * @author heyingcheng
 * @date 2025/7/19
 */
@RestController
@RequestMapping("/creative/idea")
public class CreativeIdeaController extends BaseController {

    private final ICreativeIdeaService creativeIdeaService;

    public CreativeIdeaController(ICreativeIdeaService creativeIdeaService) {
        this.creativeIdeaService = creativeIdeaService;
    }

    /**
     * 我的灵感创意列表
     *
     * @return {@link AjaxResult } 列表数据
     */
    @PreAuthorize("@ss.hasPermi('creative:idea:my')")
    @PostMapping("/my")
    public TableDataInfo myList(@RequestBody @Validated CreativeIdeaMyDTO dto) {
        startPage(dto.getPageNum(), dto.getPageSize());
        return getDataTable(creativeIdeaService.getMyList(dto));
    }

    /**
     * 获取灵感创意详细信息
     *
     * @param id ID
     * @return {@link AjaxResult } 详细信息
     */
    @PreAuthorize("@ss.hasPermi('creative:idea:get')")
    @GetMapping(value = "get")
    public AjaxResult get(@RequestParam String id) {
        return success(creativeIdeaService.get(id));
    }

    /**
     * 新增灵感创意
     *
     * @param dto 灵感创意信息
     * @return {@link AjaxResult} 新增结果
     */
    @PreAuthorize("@ss.hasPermi('creative:idea:add')")
    @PostMapping("add")
    public AjaxResult add(@RequestBody @Validated CreativeIdeaAddDTO dto) {
        return toAjax(creativeIdeaService.add(dto));
    }

    /**
     * 修改灵感创意
     * 
     * @param dto 灵感创意信息
     * @return {@link AjaxResult} 修改结果
     */
    @PreAuthorize("@ss.hasPermi('creative:idea:edit')")
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody @Validated CreativeIdeaEditDTO dto) {
        return toAjax(creativeIdeaService.edit(dto));
    }

    /**
     * 删除灵感创意
     *
     * @param id ID
     * @return {@link AjaxResult} 删除结果
     */
    @PreAuthorize("@ss.hasPermi('creative:idea:delete')")
    @PostMapping("delete")
    public AjaxResult delete(@RequestBody List<String> ids) {
        return toAjax(creativeIdeaService.removeBatchByIds(ids));
    }

    /**
     * 新增灵感创意
     *
     * @param recordId 热榜记录ID
     * @return {@link AjaxResult} 新增结果
     */
    @PreAuthorize("@ss.hasPermi('creative:idea:add')")
    @PostMapping("add/by/record")
    public AjaxResult addByRecord(@RequestParam String recordId) {
        return toAjax(creativeIdeaService.addByRecord(recordId));
    }

}